home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
336_01
/
edipal.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-27
|
15KB
|
629 lines
/*
* E D I P A L . C
*
* written by marwan el-augi 14-oct-1990 v1.0
*
*
* EGA/VGA palette editor for specific purpose
*
* Copyright (c) 1990 by Marwan EL AUGI, MEASoftlines,France.
* Copyright (c) 1987,1988 by Borland International
* for some parts of the graphics routines.
*
* No part (partial or total) may be modified without mentioning
* the above copyrights provided the fact that you don't either
* change the original name of the software (edipal.*).
*
* Despite these restrictions you can copy and distribute the software
* knowing that it is available in shareware form which is a user
* supported way of selling , you benefit from the try-before-buy
* concept. So if you find that it is useful to you or that the source
* is valuable to you, please send a contribution of 5 US$ to the address
* below.
*
* To help improve it send any comment to :
*
*
* Mr. Marwan EL-AUGI
* Res. PROBY BAT.A5 App.527
* 115, imp. Villehardouin
* F-34090 MONTPELLIER
* FRANCE
*
*
*/
/*
HEADER: ;
TITLE: EDIPAL
VERSION: 1.0;
DESCRIPTION: "Lets you view, edit and save an EGA color palette."
The whole program is in graphics mode and will
run with EGA and mostly with VGA. You can edit
modify any of the 16 colors of the palette
(any to all at once) choosing the new color from
the 64 colors set of any EGA compatible card.
KEYWORDS: EGA_colors,editor, palette;
SYSTEM: DOS 3.21 and higher
FILENAME: EDIPAL.C & OUT.C (provided with companion compiled
.exe files)
WARNINGS: needs a TurboC to compile (copyrighted to Borland
International)
Some routines are copyrighted to Borland International
these routines are mentioned in the source file
and must not be copied without clear mention
in source and executable of the following statement :
"Copyright (c) 1987,1988 Borland International"
SEE-ALSO: README.DOC, OUT.C, ega.pal,
AUTHOR : Marwan EL-AUGI
COMPILERS: TurboC 2.0 (should compile with v1.5);
*/
/* include files */
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
/* some #defines' */
#define ESC 0x1b /* define ESC key */
#define TRUE 1 /* handy constants */
#define FALSE 0
#define END 0
#define CONT 1
#define SAVE 3
#define ABNORMAL 1
#define ERROR 2
#define NORMAL 0
/* message in a msg... form used in edipal.c */
char *msgcop1 = "Copyright (c) 1990 by Marwan El-Augi, MEASoftlines, France";
char *msgcop2 = "Copyright (c) 1987,1988 by Borland International";
char *msggiv = "Give the color number :";
char *msgerr1 = "Abnormal program termination";
char *msgbye = "Good Bye from EDIPAL by MEASoftlines...";
char *msgstd = "ESC aborts or press a key to continue...";
char *msgent = "Esc aborts or press a key to begin process...";
char *msgentry = "Enter the colors now or press ESC to change palette";
char *msginp1 = "Invalid entry, only 0 to 6 are allowed : try again...";
char *msginp2 = "Invalid entry, only 0 to 9 are allowed : try again...";
char *msgcont = "ESC saves your palette or press a key to continue editing";
char *msgsav = "Press Y/y for saving new palette or any key aborts";
char *msgsure = "Are you sure ? ESC aborts or any key for yes";
char *msgext = "Press ESC for exiting";
char *msginit = "The initial palette configuration";
char *msgnew = "The modified palette configuration";
char *msgend1 = "The Quit/Save ending screen showing your palette";
char *msged = "Now you can change the palette settings";
char *msgset = "Now the new palette is set as you see it on the screen";
char *msgbeg[] = {"Graphics device :",
"Graphics mode :",
"Screen resolution :",
"Available colors :",
"Actual color :",
"Current fill color :"};
/* some useful global variables */
int graphdriver; /* graph device driver ega, vga... */
int graphmode; /* graphics mode value */
int MaxX, MaxY; /* maximal screen resolution */
int Maxcolors; /* maximal number of colors avail. */
int errorcode; /* graphics errors code variables */
struct palettetype oldpal,newpal; /* palette variables */
/*
* function prototypes
*/
void init(void); /* graphics initialization function */
void graphstat(void); /* prints report of the actual config. */
void editpal(void); /* EGA palette editing */
void colorprint(char *msg); /* print the palette */
void mainscreen(char *header); /* formats a screen and writes on it */
void drawborder(void); /* draws a border */
void pause(char *header, int flag); /* pauses and waits for a key */
void bye(void); /* exits the program giving a status */
void end(int status); /* the real exit routine */
void save(void); /* save the palette config */
void statlin(char *msg); /* prints a status line */
void getcolors(void); /* gets the new numbers of the palette */
char input1(void); /* gets the first color digit */
char input2(void); /* gets the second color digit */
/*
*
* main() : Main function
*
*/
void main(void)
{
init(); /* init graphics mode */
graphstat(); /* report mode and configuration settings */
colorprint(msginit);
pause(msgstd,END);
editpal(); /* actual main function of modifying palet.*/
end(NORMAL);
}
/*
*
* functions library
*
*/
/* init() : initialization function */
void init(void)
{
graphdriver = DETECT; /* autodetection of driver requested ega...*/
initgraph( &graphdriver, &graphmode, ""); /* init graph mode */
errorcode = graphresult(); /* exit if an error */
if( errorcode != grOk ) /* occured at init time */
{
printf(" Graphics System error : %s\n",grapherrormsg( errorcode));
end(ERROR);
}
getpalette( &oldpal ); /* save actual palette */
getpalette( &newpal ); /* initialize both palettes */
/* newpal = oldpal is another solution */
Maxcolors = getmaxcolor() + 1; /* maximal number of colors */
MaxX = getmaxx(); /* get size of screen*/
MaxY = getmaxy();
}
/* graphstat() : actual configuration function */
void graphstat(void)
{
struct fillsettingstype fillinfo;
char *driver, *mode;
char xval[3], yval[3], Max[3], filcol[3], curcol[3];
int height , width;
int i,j;
getfillsettings( &fillinfo );
mainscreen( "Actual Graphics System configuration" );
settextjustify(LEFT_TEXT, TOP_TEXT);
driver = getdrivername();
mode = getmodename(graphmode); /* get current settings */
height = textheight("H");
width = textwidth( "W");
MaxX = getmaxx(); itoa(MaxX, xval, 10);
MaxY = getmaxy(); itoa(MaxY, yval, 10);
itoa(Maxcolors, Max, 10);
itoa(getcolor(), curcol, 10);
itoa(fillinfo.color, filcol, 10);
/* prints the configuration */
for (i=2,j=0; i <= 12; i+=2,j++)
{
outtextxy(25, i * height, msgbeg[j]);
}
outtextxy(27 * width, 2 * height, driver );
outtextxy(27 * width, 4 * height, mode);
outtextxy(27 * width, 6 * height, "( 0 , 0 , , )");
outtextxy(37 * width, 6 * height, xval );
outtextxy(43 * width, 6 * height, yval );
outtextxy(27 * width, 8